package cn.sangedon.review.data.controller;

import cn.sangedon.review.common.service.data.DropLimitService;
import cn.sangedon.review.common.service.data.RiseLimitService;
import cn.sangedon.review.common.service.data.TradingDateService;
import cn.sangedon.review.common.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股市基础信息controller
 */
@Api(tags = "股票基础信息")
@RestController
@RequestMapping("base")
public class StockBaseController {
    @Autowired
    private TradingDateService tradingDateService;

    @Autowired
    private RiseLimitService riseLimitService;

    @Autowired
    private DropLimitService dropLimitService;

    /**
     * 获取最近的几个交易日期
     * SELECT * FROM tb_rise_limit WHERE trade_date = (SELECT MAX(trade_date) FROM tb_rise_limit);
     *
     * @param num 最近几个，默认为最近一个
     * @return
     */
    @ApiOperation("获取最近的几个交易日期")
    @GetMapping("latest_trading_day")
    public Result getLatestTradingDay(@RequestParam(value = "num", defaultValue = "1") Integer num) {
        return Result.okBuilder().data(tradingDateService.getLatestTradingDay(num)).build();
    }

    /**
     * 获取最近交易日涨停股票
     *
     * @return
     */
    @ApiOperation("获取最近交易日涨停股票")
    @GetMapping("latest_rise_limit")
    public Result listLatestRiseLimit() {
        return Result.okBuilder().data(riseLimitService.listLatestRiseLimit()).build();
    }

    /**
     * 获取最近交易日跌停股票
     *
     * @return
     */
    @ApiOperation("获取最近交易日跌停股票")
    @GetMapping("latest_drop_limit")
    public Result listLatestDropLimit() {
        return Result.okBuilder().data(dropLimitService.listLatestDropLimit()).build();
    }
}
